package com.asset.dispoal.business.bsAgreement.service.commom;

import com.asset.dispoal.business.bsAgreement.dto.MergeDownloadRequest;
import com.asset.dispoal.business.bsAgreement.dto.MergeDownloadResponse;
import com.asset.dispoal.business.merge.domain.db.mapper.MergeDownloadMapper;
import com.asset.dispoal.commom.page.PagingQuery;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import tech.mhuang.pacebox.core.ddd.BaseCommand;
import tech.mhuang.pacebox.springboot.protocol.Result;
import tech.mhuang.pacebox.springboot.protocol.data.Page;
import tech.mhuang.pacebox.springboot.protocol.data.PageVO;

import java.util.List;

@Component
@Slf4j
public class PageMergeDownloadCommand implements BaseCommand<MergeDownloadRequest, Result<PageVO<MergeDownloadResponse>>> {

    @Autowired
    private MergeDownloadMapper mergeDownloadMapper;

    @Override
    public Result<PageVO<MergeDownloadResponse>> execute(MergeDownloadRequest mergeDownloadRequest) {
        int count = mergeDownloadMapper.queryPageCount(mergeDownloadRequest);
        Page<MergeDownloadRequest> page = PagingQuery.getPage(count, mergeDownloadRequest);
        PageVO<MergeDownloadResponse> pageVO = new PageVO<>();
        pageVO.setTotalSize(count);
        if (page != null) {
            List<MergeDownloadResponse> bsCases = mergeDownloadMapper.queryPage(page);
            pageVO.setResult(bsCases);
        }
        return Result.ok(pageVO);
    }
}
